﻿package net.wangit.dev.dataprivilege;

import net.wangit.context.ActionContext;
import net.wangit.dev.DomainAction;
import net.wangit.dev.ObjectChecker;
import net.wangit.jdbc.DB;
import net.wangit.user.privilege.DataPrivilegeCache;
import net.wangit.util.Checker;

public class DeleteDataPrivilegeAction extends DomainAction {

	private static final String SQL_CHECK = "select l from DPCONFIG where dpid=?";
	private static final String SQL_CONFIG = "delete from DPCONFIG where dpid=?";
	private static final String SQL_DP = "delete from DP where dpid=?";

	public DeleteDataPrivilegeAction() {
	}

	public void doAction(DB db, ActionContext ac) throws Exception {
		String dpid = ac.getRequestParameter("dpid");
		if (!Checker.isEmpty(dpid)) {
			net.wangit.MapList list = db.query(
					DeleteDataPrivilegeAction.SQL_CHECK, dpid, 2);
			if (ObjectChecker.invalid(ac, list, "l"))
				return;
			db.execute(DeleteDataPrivilegeAction.SQL_CONFIG, dpid, 2);
			db.execute(DeleteDataPrivilegeAction.SQL_DP, dpid, 2);
			DataPrivilegeCache.clearAll(domain);
			DataPrivilegeReferenceHelper.update(db, domain, dpid, "");
		}
	}
}
